package cn.jlearn.proxy.web.utils;

import cn.jlearn.proxy.web.pojo.BaseEnum;
import cn.jlearn.proxy.web.pojo.Option;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qianyingchao
 * @version 1.0
 * @date 2021/7/16 1:55 下午
 */
public class EnumUtil {

    public static Map<String, String> toMap(BaseEnum<String, String>[] baseEnums) {
        Map<String, String> map = new HashMap<>(baseEnums.length);
        for (BaseEnum<String, String> baseEnum : baseEnums) {
            map.put(baseEnum.getCode(), baseEnum.getRemark());
        }
        return map;
    }

    public static List<Option> toList(BaseEnum<String, String>[] baseEnums) {
        List<Option> options = new ArrayList<>(baseEnums.length);
        for (BaseEnum<String, String> baseEnum : baseEnums) {
            options.add(new Option(baseEnum.getCode(), baseEnum.getRemark()));
        }
        return options;
    }

}
